package com.bangwz.io;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;

/**
 * 字符流
 * 
 * @author venus
 * @E-mail: dongyz@xcbobo.com
 * @qq: 416331017
 * @version 创建时间：2018年4月7日 下午9:43:57
 *
 */
public class ReaderAndWriter {
	public static void main(String[] args) {
		copy("‪D:\\aa.txt", "‪D:\\bb.txt");
	}

	/**
	 * 文件复制
	 * 
	 * @param src
	 * @param des
	 */
	@SuppressWarnings("resource")
	public static void copy(String src, String des) {
		File src_f = new File(src);
		File des_f = new File(des);
		FileInputStream fis = null;
		FileOutputStream fos = null;
		try {
			fis = new FileInputStream(src_f);
			fos = new FileOutputStream(des_f);

			InputStreamReader inputStreamReader = new InputStreamReader(fis);

			OutputStreamWriter outputStreamWriter = new OutputStreamWriter(fos);

			BufferedReader bufferedReader = new BufferedReader(inputStreamReader);

			BufferedWriter bufferedWriter = new BufferedWriter(outputStreamWriter);

			String s;
			try {
				while ((s = bufferedReader.readLine()) != null) {
					System.out.println(s);
					bufferedWriter.write(s);
				}
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			// int ch;
			// try {
			// while ((ch = fis.read()) != -1) {
			// System.out.println((char) ch);
			// fos.write(ch);
			// }
			// } catch (IOException e) {
			// // TODO Auto-generated catch block
			// e.printStackTrace();
			// }
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally {
			try {
				fis.close();
			} catch (IOException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
			try {
				fos.close();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}
}
